window.onload=function(){
    show()

}



var dx=[];
//JSON对象，适应于网络传输
dx[0]={
    title:'能实现响应式开发的框架是（ ）。',
    options:{
        A:'JavaScript',
        B:'CSS',
        C:'HTML5',
        D:'Bootstrap'
    },
    key:'D'
};
dx[1]={title:'花生播种前常要松土的主要原因是种子萌发需要(　　)',
    options:{A:'充足的空气',
        B:'适宜的温度',
        C:'适量的水分',
        D:'一定的光照'
    },
    key:'A'
};
dx[2]={title:'下列几类种子在适宜的环境条件下可能萌发的是(　　)',
    options:{A:'煮熟的种子',
        B:'被虫子咬掉胚的种子',
        C:'正处于休眠期的种子',
        D:'保存完好的种子'
    },
    key:'D'
};

var answer=[]
var useranswer=[]
var number=0
var point=0

for (let x=0;x<dx.length;x++){
    answer.push(dx[x].key)
    useranswer.push("*")
    console.log(answer,useranswer)
    }


function show(){
    document.getElementById("prev").disabled=""
    document.getElementById("next").disabled=""
    document.getElementById("title").innerText=dx[number].title
   var currentQuestion=dx[number]
    var x=document.getElementsByName("option")
   for(let i of x){
    i.checked=false
   }
   document.getElementById("choice-a").innerText=currentQuestion.options.A
   document.getElementById("choice-b").innerText=currentQuestion.options.B
   document.getElementById("choice-c").innerText=currentQuestion.options.C
   document.getElementById("choice-d").innerText=currentQuestion.options.D
   answerRecovery()
}

function answersave(){
    var x=document.getElementsByName("option")
    for(let i of x){
    if(i.checked){useranswer[number]=i.value}
    }
console.log(useranswer)
}


function answerRecovery(){
var currentAnswer=useranswer[number]
var x=document.getElementsByName("option")
for(let i of x){
    if(currentAnswer==i.value){
        i.checked=true}

}
}

function next(){
    answersave()
if(number>=dx.length-1){
    document.getElementById("next").disabled="true"
}else{
    number++
    show()
}
}

function prev(){
    answersave()
if(number<=0){
    document.getElementById("prev").disabled="true"
}else{
    number--
    show()
}
}

function submit(){
    answersave()
    document.getElementById("answerblank").style.display="none"
    for(i of useranswer){
        if(i==answer[useranswer.indexOf(i)]){point+=10}   
    }
    alert(point)
}